const fs = require("fs").promises;
const { ifWhiteList } = require("./whiteList");

async function deleteImage(fileName) {
  try {
    if (ifWhiteList(fileName)) {
      return true;
    }
    const filePath = `upload/image/${fileName}`;
    try {
      await fs.unlink(filePath);
      return true;
    } catch (error) {
      if (error.code === 'ENOENT') {
        return null;
      } else {
        throw error;
      }
    }
  } catch (error) {
    console.error('Error:', error);
    return false;
  }
}

exports.create = async (fileName) => {
  return await deleteImage(fileName);
};
